package com.xiangxiao.rpan.data.controller;

import com.xiangxiao.rpan.data.constant.ResponseCode;
import com.xiangxiao.rpan.data.constant.ResponseMessage;
import com.xiangxiao.rpan.data.dto.JsonObject;
import com.xiangxiao.rpan.data.entity.KafkaAlarm;
import com.xiangxiao.rpan.data.exception.DataException;
import com.xiangxiao.rpan.data.service.MessageAlarmSendService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;

/**
 * @Projectname: rpan-data
 * @Author: xiangxiao
 * @Email: 573768011@qq.com
 * @Data:2024/6/3 0:09
 */
@RestController
@RequestMapping("/api")
public class MessageAlarmController {
  @Resource
  private MessageAlarmSendService messageAlarmService;

  /**
   * 参数格式如下
   * successed:
   * {
   *   "data": [
   *      {
   *        "type": 0,
   *         "fileId": "d42f41f45fa6d73778ecef3cf0d1229b监所批量建档图片.zip",
   *         "name": "监所批量建档图片.zip",
   *         "filePath": "/root/rpan/2024/6/17/6648EC95F0C7477DBAE0497B3275A763/监所批量建档图片.zip",
   *         "fileExtension": ".zip",
   *         "size": 372905,
   *         "status": 1,
   *         "startTime": "2024-07-08 14:09:19",
   *         "finishTime": "2024-07-08 14:09:47",
   *         "time": "2024-07-08 14:09:48",
   *         "operator": "xiangxiao"
   *       }
   *     ],
   *   "type": 0
   * }
   *
   * failed:
   *{
   *   "data": [
   *     {
   *       "type": 0,
   *       "fileId": "d42f41f45fa6d73778ecef3cf0d1229b监所批量建档图片.zip",
   *       "name": "监所批量建档图片.zip",
   *       "filePath": "/root/rpan/2024/6/17/6648EC95F0C7477DBAE0497B3275A763/监所批量建档图片.zip",
   *       "fileExtension": ".zip",
   *       "size": 372905,
   *       "status": 0,
   *       "startTime": null,
   *       "finishTime": null,
   *       "time": "2024-07-08 14:09:48",
   *       "operator": "xiangxiao"
   *     }
   *   ],
   *   "type": 0
   * }
   * */
  @PostMapping("/file/upload/alarm")
  public JsonObject sendFileUploadAlarm(@RequestBody KafkaAlarm alarm) {
    try {
      messageAlarmService.sendOutAlarm(alarm);
      return new JsonObject(ResponseMessage.SEND_FILE_UPLOAD_ALARM_SUCEESS, ResponseCode.OK);
    } catch (DataException e) {
      e.printStackTrace();
      return new JsonObject(ResponseMessage.SEND_FILE_UPLOAD_ALARM_FAILED, ResponseCode.SEND_FILE_UPLOAD_ALARM_FAILED);
    }
  }

  /**
   * 参数格式如下
   * successed:
   * {
   *   "data": [
   *     {
   *       "type": 0,
   *       "fileId": "3cd25d3f2ca70fae2e0532eb3860de2e微服务指标-Prometheus采集监控实践.pdf",
   *       "name": "微服务指标-Prometheus采集监控实践.pdf",
   *       "savePath": "C:/Users/admin/Downloads/微服务指标-Prometheus采集监控实践片.pdf",
   *       "fileExtension": ".pdf",
   *       "status": 1,
   *       "size": 2725416,
   *       "startTime": "2024-07-08 11:17:52",
   *       "finishTime": "2024-07-08 11:20:34",
   *       "time": "2024-07-08 11:20:36",
   *       "operator": "xiangxiao"
   *     }
   *   ],
   *   "type": 1
   * }
   *
   *failed:
   *{
   *   "data": [
   *     {
   *       "type": 0,
   *       "fileId": "3cd25d3f2ca70fae2e0532eb3860de2e微服务指标-Prometheus采集监控实践.pdf",
   *       "name": "微服务指标-Prometheus采集监控实践.pdf",
   *       "savePath": "C:/Users/admin/Downloads/微服务指标-Prometheus采集监控实践片.pdf",
   *       "fileExtension": ".pdf",
   *       "status": 0,
   *       "size": 2725416,
   *       "startTime": null,
   *       "finishTime": null,
   *       "time": "2024-07-08 11:20:36",
   *       "operator": "xiangxiao"
   *     }
   *   ],
   *   "type": 1
   * }
   * */
  @PostMapping("/file/download/alarm")
  public JsonObject sendFileDOwnloadAlarm(@RequestBody KafkaAlarm alarm) {
    try {
      messageAlarmService.sendOutAlarm(alarm);
      return new JsonObject(ResponseMessage.SEND_FILE_DOWNLOAD_ALARM_SUCEESS, ResponseCode.OK);
    } catch (DataException e) {
      e.printStackTrace();
      return new JsonObject(ResponseMessage.SEND_FILE_DOWNLOAD_ALARM_FAILED, ResponseCode.SEND_FILE_DOWNLOAD_ALARM_FAILED);
    }
  }

  /**
   * 入参格式如下
   * successed:
   * {
   *   "data": [
   *       {
   *           "type": 1,
   *           "floderPath": "/root/rpan/2024/2/28/264E8E4B7FAC4627BBA8DADD6605DFED",
   *           "childList": [],
   *           "status": 1,
   *           "startTime": "2024-07-08 15:46:02",
   *           "finishTime": "2024-07-08 15:46:40",
   *           "time": "2024-07-08 15:46:41",
   *           "operator": "xiangxiao"
   *       }
   *   ],
   *   "type": 2
   * }
   *
   * failed:
   * {
   *       "data": [
   *           {
   *               "type": 1,
   *               "floderPath": "/root/rpan/2024/2/28/264E8E4B7FAC4627BBA8DADD6605DFED",
   *               "childList": [],
   *               "status": 0,
   *               "startTime": null,
   *               "finishTime": null,
   *               "time": "2024-07-08 15:46:41",
   *               "operator": "xiangxiao"
   *           }
   *       ],
   *       "type": 2
   *     }
   * */
  @PostMapping("/floder/upload/alarm")
  public JsonObject sendFloderUploadAlarm(@RequestBody KafkaAlarm alarm) {
    try {
      messageAlarmService.sendOutAlarm(alarm);
      return new JsonObject(ResponseMessage.SEND_FLODER_UPLOAD_ALARM_SUCEESS, ResponseCode.OK);
    } catch (DataException e) {
      e.printStackTrace();
      return new JsonObject(ResponseMessage.SEND_FLODER_UPLOAD_ALARM_FAILED, ResponseCode.SEND_FLODER_UPLOAD_ALARM_FAILED);
    }
  }

  /**
   * 入参格式如下
   * successed:
   * {
   *   "data": [
   *     {
   *       "type": 1,
   *       "savePath": "C:/Users/admin/Downloads",
   *       "childList": [],
   *       "status": 1,
   *       "startTime": "2024-07-08 15:09:02",
   *       "finishTime": "2024-07-08 15:09:40",
   *       "time": "2024-07-08 15:09:41",
   *       "operator": "xiangxiao"
   *     }
   *   ],
   *   "type": 3
   * }
   *
   * failed:
   *{
   *   "data": [
   *     {
   *       "type": 1,
   *       "savePath": "C:/Users/admin/Downloads",
   *       "childList": [],
   *       "status": 0,
   *       "startTime": null,
   *       "finishTime": null,
   *       "time": "2024-07-08 15:09:41",
   *       "operator": "xiangxiao"
   *     }
   *   ],
   *   "type": 3
   * }
   * */
  @PostMapping("/floder/download/alarm")
  public JsonObject sendFloderDownloadAlarm(@RequestBody KafkaAlarm alarm) {
    try {
      messageAlarmService.sendOutAlarm(alarm);
      return new JsonObject(ResponseMessage.SEND_FLODER_DOWNLOAD_ALARM_SUCEESS, ResponseCode.OK);
    } catch (DataException e) {
      e.printStackTrace();
      return new JsonObject(ResponseMessage.SEND_FLODER_DOWNLOAD_ALARM_FAILED, ResponseCode.SEND_FLODER_DOWNLOAD_ALARM_FAILED);
    }
  }
}
